package com.cnhis.cloudhealth.clinical.hosnurse.hoscharge.bo;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cnhis.cloudhealth.clinical.hosnurse.hoscharge.dao.HoschargeDao;
import com.cnhis.cloudhealth.clinical.hosnurse.hospatient.bo.HosPatientBo;
import com.cnhis.cloudhealth.clinical.hosnurse.hossendadvice.bo.HosSendAdviceBo;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.newid.GetNewId;
import com.cnhis.cloudhealth.commons.utils.DateUtils;
import com.cnhis.cloudhealth.commons.utils.JsonUtil;
import com.cnhis.cloudhealth.commons.utils.Page;
import com.cnhis.cloudhealth.commons.utils.StaticKeys;

import net.sf.json.JSONObject;

@SuppressWarnings({ "rawtypes", "unchecked" })
@Service
public class HoschargeBo {
	@Resource
	private HoschargeDao hoschargeDao;
	@Resource
	private GetNewId getNewId;
	@Resource
	private HosPatientBo hosPatientBo;
	@Resource
	private HosSendAdviceBo hosSendAdviceBo;

	public ModelVo search(Map map) throws Exception {
		ModelVo mo = new ModelVo();
		List ls = null;
		try {
			ls = hoschargeDao.search(map);

		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(ls);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(ls);
		return mo;
	}

	private int getWorkingMode() throws Exception {
		return hoschargeDao.getWorkingMode();
	}

	// HOPublic_VBX1_Update 业务通知单
	public void execHOPublic_VBX1_Update(Map map) throws Exception {
		hoschargeDao.HOPublic_VBX1_Update(map);

	}

	public ModelVo execHORate_VAJ2_Update(Map map) throws Exception {
		ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
		String xml = map.get("Xml").toString();
		JSONObject jsonObject = JSONObject.fromObject(xml);
		Map<String, Object> vaa1 = JsonUtil.getMap(jsonObject.getJSONObject("VAA1").toString());
		List<Map<String, Object>> vai1 = JsonUtil.getList(jsonObject.getJSONArray("VAI1").toString());
		List<Map<String, Object>> vaj1 = JsonUtil.getList(jsonObject.getJSONArray("VAJ1").toString());
		if (vaa1.isEmpty()) {
			vo.setResult(StaticKeys.OH_FALSE);
			vo.setResultMsg("病人信息不能为空");
			return vo;
		}
		if (vaa1.get("bck01a") == null || "0".equals(vaa1.get("bck01a").toString())) {
			vo.setResult(StaticKeys.OH_FALSE);
			vo.setResultMsg("病人科室不能为空");
			return vo;
		}

		if (vaa1.get("vaa01") == null || "0".equals(vaa1.get("vaa01").toString())) {
			if ((vaa1.get("vaa03") == null || "".equals(vaa1.get("vaa03").toString()))
					|| (vaa1.get("vaa05") == null || "".equals(vaa1.get("vaa05").toString()))) {
				vo.setResult(StaticKeys.OH_FALSE);
				vo.setResultMsg("病人姓名门诊号不能为空");
				return vo;

			}
		}
		if (vai1.size() == 0) {
			vo.setResult(StaticKeys.OH_FALSE);
			vo.setResultMsg("病人单据信息不能为空");
			return vo;

		}
		if (vaj1.size() == 0) {
			vo.setResult(StaticKeys.OH_FALSE);
			vo.setResultMsg("病人收费记录信息不能为空");
			return vo;

		}
		if (checkBCK01D(vaj1)) {
			vo.setResult(StaticKeys.OH_FALSE);
			vo.setResultMsg("病人收费记录执行科室不能为空");
			return vo;
		}
		// 修改vae1住院医师
		if ("2".equals(vaa1.get("acf01").toString())) {
			Map map1 = getBCE01C_BCE03C(vaa1.get("vaa07").toString());
			vaj1 = updateVAJ1(map1, vaj1);

		}
		// 血库记账
		if (checkVAI05(vai1) || "4".equals(vaa1.get("acf01").toString())) {
			vaj1 = updateVAJ1_VAJ53(vaj1, vai1);
		}
		vaj1 = updateVAJ1_VAI01(vaj1, vai1);
		long VAA07;
		long VAA01;
		int ACF01;
		// long BBY01;
		// long VAJ01;
		// long BCK01A;
		long BCK01B;
		long InDept = 0;
		long InWard = 0;
		// long VAI01A;
		long BCK01D;
		long BCE01A;
		long EmpId;
		long KuoZhan1 = 0;
		// long ErrId;
		// long IsHyType;
		// long VBU01;
		long VAI18;
		// long Result;
		// int ABC14;
		// String BDN01;
		String WorkName;
		// String BCE02A;
		// String BCE03A;
		int WorkType;
		int WorkFrom;
		// String VAI00;
		String EmpNo;
		// String BDP02;
		String ABC02;
		String EmpName;
		// BigDecimal VAJ24;
		// BigDecimal VAJ25;
		// BigDecimal VAJ30;
		// BigDecimal VAJ31;
		// BigDecimal VAJ32;
		// BigDecimal VAJ33;
		// BigDecimal VAJ34;
		// String VAJ35;
		String FAB03 = null;
		Double TotalFee;
		// String VCB04;
		// BigDecimal VAI22;
		// BigDecimal VAI23;
		long VAP01;
		// long DSK01;
		long VAJ10 = 0;
		long VCY01;
		long BCK01E;
		long BCK01F = 0;
		String BCQ04 = null;
		VAA01 = Long.parseLong(vaa1.get("vaa01").toString());
		VAA07 = Long.parseLong(vaa1.get("vaa07").toString());
		ACF01 = Integer.parseInt(vaa1.get("acf01").toString());
		WorkName = vaa1.get("workname").toString();
		WorkType = vaa1.get("worktype") == null ? 0 : Integer.parseInt(vaa1.get("worktype").toString());
		EmpId = Long.parseLong(vaa1.get("empid").toString());
		EmpNo = vaa1.get("empno").toString();
		EmpName = vaa1.get("empname").toString();
		// BCK01A = Long.parseLong(vaa1.get("bck01a").toString());
		WorkFrom = vaa1.get("workfrom") == null ? 0 : Integer.parseInt(vaa1.get("workfrom").toString());
		BCK01B = vaa1.get("bck01b") == null ? 0 : Long.parseLong(vaa1.get("bck01b").toString());
		BCE01A = vaa1.get("bce01a") == null ? 0 : Long.parseLong(vaa1.get("bce01a").toString());

		// BCE02A = vaa1.get("bce02a").toString();
		// BCE03A = vaa1.get("bce03a").toString();
		// BDP02 = vaa1.get("bdp02").toString();
		ABC02 = vaa1.get("abc02").toString();
		// VBU01 = Long.parseLong(vaa1.get("vbu01").toString());
		// VCB04 = vaa1.get("vcb04").toString();
		VAP01 = vaa1.get("vap01") == null ? 0 : Long.parseLong(vaa1.get("vap01").toString());
		VCY01 = vaa1.get("vcy01") == null ? 0 : Long.parseLong(vaa1.get("vcy01").toString());
		long VAI01 = getNewId.nextId();
		if (ACF01 == 2) {
			if (checkPatient9(VAA07)) {
				vo.setResult(StaticKeys.OH_FALSE);
				vo.setResultMsg("取消入院病人不允许记账");
				return vo;
			}
			if (checkPatient5(VAA07)) {
				vo.setResult(StaticKeys.OH_FALSE);
				vo.setResultMsg("出院病人不允许记账");
				return vo;
			}
			if (checkParam()) {
				if (checkPatient4(VAA07)) {
					vo.setResult(StaticKeys.OH_FALSE);
					vo.setResultMsg("预出院病人不允许记账");
					return vo;
				}
			}
			Map m = new HashMap();
			m.put("VAA07", VAA07);
			m.put("VAA01", VAA01);
			if (checkPatient(m)) {
				vo.setResult(StaticKeys.OH_FALSE);
				vo.setResultMsg("病人就诊记录不存在，不能进行记账操作");
				return vo;
			}
		}

		Map m1 = new HashMap();
		m1.put("ABC02", ABC02);
		m1.put("VAA01", VAA01);
		if (checkParam1() && checkPatient_VBU01(m1)) {
			vo.setResult(StaticKeys.OH_FALSE);
			vo.setResultMsg("已绑定会员卡类型，禁止修改病人费别");
			return vo;
		}
		if (BCE01A > 0) {
			if (checkBCE1(BCE01A)) {
				vo.setResult(StaticKeys.OH_FALSE);
				vo.setResultMsg("开单医生不在职，不能进行记账操作");
				return vo;
			}
		}
		if (checkBCK01B(vai1)) {
			vo.setResult(StaticKeys.OH_FALSE);
			vo.setResultMsg("存在收费单据开单科室为空");
			return vo;
		}
		if (checkBCE02A(vai1) && WorkType != 1) {
			vo.setResult(StaticKeys.OH_FALSE);
			vo.setResultMsg("存在收费单据开单人为空");
			return vo;
		}
		if (checkBCK01C(vaj1) && WorkType != 1) {
			vo.setResult(StaticKeys.OH_FALSE);
			vo.setResultMsg("病人收费记录开单科室不能为空");
			return vo;
		}
		if (checkBCE02B(vaj1) && WorkType != 1) {
			vo.setResult(StaticKeys.OH_FALSE);
			vo.setResultMsg("病人收费记录开单医生不能为空");
			return vo;
		}
		if (checkParam2()) {
			if (checkBCK01E(vaj1)) {
				vo.setResult(StaticKeys.OH_FALSE);
				vo.setResultMsg("领药科室不能为空");
				return vo;
			}
		}
		if (WorkFrom == 2 && WorkType == 5) {
			if (vaa1.get("kuozhan1") == null || "0".equals(map.get("kuozhan1").toString())) {
				vo.setResult(StaticKeys.OH_FALSE);
				vo.setResultMsg("手术记账未传入手术ID");
				return vo;
			}
		}
		// IsHyType = getWorkingMode();
		// ABC14 = getABC14(ABC02);
		List tmpNewVAI1 = tmpNewVAI1(vai1);
		List tmpNewVAJ1 = tmpNewVAJ1(vaj1);
		List tmpOldVAJ1 = tmpOldVAJ1(vaj1);

		if (checkParam3() && WorkFrom == 2) {

			tmpNewVAJ1 = tmpNewVAJ1_VAJ53(tmpNewVAJ1);
		}
		tmpNewVAI1 = tmpNewVAI1_VAI01_VAI04_VAI22_VAI23(tmpNewVAI1, vaj1);
		vaj1 = setVAI01_VAI04(tmpNewVAI1, vai1);
		tmpNewVAJ1 = tmpNewVAJ1_VAJ01(tmpNewVAJ1, vai1);
		vaj1 = VAJ1_VAJ01(vaj1, vai1);
		tmpOldVAJ1 = tmpOldVAJ1_VAJ24_VAJ25(tmpOldVAJ1);
		tmpNewVAJ1 = tmpNewVAJ1_VAJ24_VAJ25(tmpNewVAJ1);

		TotalFee = getTotalFee(tmpNewVAJ1);
		HashMap hs = new HashMap();
		hs.put("tmpVAJ1", tmpNewVAJ1);

		List<Map<String, Object>> dpt1 = hoschargeDao.getDept(hs);
		hs.put("tmpVAJ1", vaj1);
		// 通知
		List<Map<String, Object>> TmpForMedicine = hoschargeDao.getTmpForMedicine(hs);

		if (ACF01 == 2) {
			Map mm1 = hoschargeDao.getBCK01D_BCK01C_BCQ04B(VAA07);
			InDept = Long.parseLong(mm1.get("indept").toString());
			InWard = Long.parseLong(mm1.get("inward").toString());
			BCQ04 = mm1.get("bcq04b").toString();
			BCK01F = hoschargeDao.getBCK01A(mm1.get("bcq04b").toString());

		}
		if (WorkFrom == 2) {
			KuoZhan1 = Integer.parseInt(vaa1.get("kuozhan1").toString());

		} else if (WorkFrom == 3) {
			VAJ10 = Integer.parseInt(vaa1.get("kuozhan1").toString());
		} else {
			KuoZhan1 = 0;
			VAJ10 = 0;
		}
		if (WorkType == 3 || WorkType == 4) {
			VAI18 = 2;
		} else {
			VAI18 = WorkType;

		}
		// 新增病人收费单据
		HashMap m = new HashMap();
		m.put("tmpVAI1", tmpNewVAI1);
		m.put("vaa01", VAA01);
		m.put("vaa07", VAA07);
		m.put("bck01b", BCK01B);
		m.put("empno", EmpNo);
		m.put("empname", EmpName);
		m.put("workname", WorkName);
		m.put("vai18", VAI18);
		m.put("kuozhan1", KuoZhan1);
		m.put("acf01", ACF01);
		m.put("vap01", VAP01);
		insertVAI2(m);
		HashMap hm = new HashMap();
		hm.put("tmpVAJ1", tmpNewVAJ1);
		hm.put("vaa01", VAA01);
		hm.put("vaa07", VAA07);
		hm.put("vai18", VAI18);
		hm.put("vaj10", VAJ10);
		hm.put("acf01", ACF01);
		hm.put("inward", InWard);
		hm.put("indept", InDept);
		hm.put("vap01", VAP01);
		hm.put("empname", EmpName);
		hm.put("workname", WorkName);
		hm.put("empno", EmpNo);
		hm.put("empname", EmpName);
		hm.put("fab03", FAB03);
		hm.put("bck01f", BCK01F);
		hm.put("bcq04", BCQ04);
		if (hoschargeDao.checkParam4() > 0 && WorkFrom == 2) {
			insertVAJT(hm);
		} else {
			insertVAJ2(hm);
		}
		// 修改病人余额
		if (ACF01 == 2 && TotalFee > 0) {
			if ((hoschargeDao.checkParam5() == 0 && WorkFrom == 2) || WorkFrom != 2) {
				HashMap hs1 = new HashMap();
				hs1.put("VBM01", 0);
				hs1.put("VAA01", VAA01);
				hs1.put("VBM03", 2);
				hs1.put("VBM04", 0);
				hs1.put("VBM05", TotalFee);
				hs1.put("VBM06", TotalFee);
				hs1.put("VAA07", VAA07);

				hosPatientBo.execHORateVBM1Update(hs1);
			}
		}
		// 私人收费项目
		map.put("BCE01", EmpId);
		map.put("BCK01", 0);
		execHORate_BGE1_Update(map);

		// 如果是医技VAJ53直接写为1
		if (WorkType == 5 && WorkFrom == 3) {
			update_VAJ53(hm);
		}
		// 更新明细VAJ53为拒绝执行
		if ("1".equals(map.get("Refuse").toString()) && ACF01 == 2) {
			hm.put("VAI01", VAI01);
			update_VAJ53_2(hm);
		}
		// 更新医生复诊计划状态
		if (VCY01 > 0) {
			HashMap mm = new HashMap();
			mm.put("VAA07", VAA07);
			mm.put("VCY01", VCY01);
			updateVCY1(mm);
		}
		if (TmpForMedicine.size() > 0) {
			String CurDate = DateUtils.getDateString(new Date());
			for (Map<String, Object> mm : TmpForMedicine) {
				BCK01D = Long.parseLong(mm.get("bck01d").toString());
				BCK01E = Long.parseLong(mm.get("bck01d").toString());
				BCK01E = Long.parseLong(mm.get("bck01e").toString());
				VAI01 = Long.parseLong(mm.get("vai01").toString());
				String VAI04 = getVAI04(tmpNewVAI1, VAI01);
				HashMap mh = new HashMap();
				mh.put("VAI01", VAI01);
				mh.put("InWard", InWard);
				mh.put("InDept", InDept);
				mh.put("BCK01D", BCK01D);
				mh.put("BCK01E", BCK01E);
				if (checkVBX1(mh)) {
					HashMap hh = new HashMap();
					hh.put("vaa01", VAA01);
					hh.put("vaa07", VAA07);
					hh.put("acf01", ACF01);
					hh.put("vbx03", 2);
					hh.put("vbx04", 2);
					hh.put("vbx05", 2);
					hh.put("vbx06", -1);
					hh.put("vbx07", VAI04);
					hh.put("vbx14", CurDate);
					hh.put("vbx18", VAI01);
					hh.put("vbx19", 0);
					hh.put("vbx20", "划价生成待发药单据");
					hh.put("vbx21", 0);
					hh.put("vbx22", 0);
					hh.put("bce01", EmpId);
					hh.put("bce03", EmpName);
					hh.put("bck01b", InDept);
					hh.put("bck01c", BCK01E);
					hh.put("bck01d", BCK01D);
					hh.put("bck01a", InWard);
					execHOPublic_VBX1_Update(hh);
				}
			}
		}
		if (dpt1.size() > 0 && checkParam6()) {
			hosSendAdviceBo.execDPSDPT1Update(dpt1);

		}
		HashMap mh = new HashMap();
		mh.put("VAI01", VAI01+"");
		vo.setMap(mh);
		return vo;
	}

	private boolean checkParam6() throws Exception {
		return hoschargeDao.checkParam6() == 0;
	}

	private boolean checkVBX1(Map map) throws Exception {
		return hoschargeDao.checkVBX1(map) == 0;

	}

	private String getVAI04(List<Map<String, Object>> vai1, Long VAI01) throws Exception {
		String VAI04 = null;
		for (Map<String, Object> map : vai1) {
			if (Long.parseLong(map.get("vai01").toString()) == VAI01) {
				VAI04 = map.get("vai04").toString();
			}
		}
		return VAI04;
	}

	private void updateVCY1(Map map) throws Exception {
		hoschargeDao.updateVCY1(map);
	}

	private void update_VAJ53_2(Map map) throws Exception {
		hoschargeDao.update_VAJ53_2(map);
	}

	private void update_VAJ53(Map map) throws Exception {
		hoschargeDao.update_VAJ53(map);
	}

	private void insertVAI2(Map map) throws Exception {
		hoschargeDao.insertVAI2(map);

	}

	private void insertVAJT(Map map) throws Exception {
		hoschargeDao.insertVAJT(map);
	}

	private void insertVAJ2(Map map) throws Exception {
		hoschargeDao.insertVAJ2(map);
	}

	private boolean checkBCK01D(List<Map<String, Object>> vaj1) throws Exception {
		boolean bool = false;
		for (Map<String, Object> map : vaj1) {
			if (map.get("bck01d") == null || "0".equals(map.get("bck01d").toString())) {
				bool = true;
				break;
			}
		}
		return bool;
	}

	private Map getBCE01C_BCE03C(String vaa07) throws Exception {
		return hoschargeDao.getBCE01C_BCE03C(vaa07);
	}

	private List<Map<String, Object>> updateVAJ1(Map map1, List<Map<String, Object>> vaj1) throws Exception {
		for (Map<String, Object> map : vaj1) {
			if(map1!=null){
				map.put("bce01e", Long.parseLong(map1.get("bce01c").toString()));
				map.put("bce03e", map1.get("bce03c").toString());
				
			}
		}
		return vaj1;
	}

	private boolean checkVAI05(List<Map<String, Object>> vai1) throws Exception {
		for (Map<String, Object> map : vai1) {
			if (map.get("vai05") != null && "血库记账".equals(map.get("vai05").toString())) {
				return true;
			}
		}
		return false;
	}

	private List<Map<String, Object>> updateVAJ1_VAJ53(List<Map<String, Object>> vaj1, List<Map<String, Object>> vai1)
			throws Exception {
		for (Map<String, Object> map : vaj1) {
			for (Map<String, Object> m : vai1) {
				if (map.get("vai00").toString().equals(m.get("vai00").toString())) {
					map.put("bck01c", Long.parseLong(m.get("bck01b").toString()));
					map.put("bce02b", m.get("bce02a").toString());
					map.put("bce03b", m.get("bce03a").toString());
					if ("血库记账".equals(m.get("vai05").toString())) {
						map.put("vaj53", 1);
					}
				}
			}
		}
		return vaj1;
	}

	private List<Map<String, Object>> updateVAJ1_VAI01(List<Map<String, Object>> vaj1, List<Map<String, Object>> vai1)
			throws Exception {
		for (Map<String, Object> map : vaj1) {
			for (Map<String, Object> m : vai1) {
				if (map.get("vai00").toString().equals(m.get("vai00").toString())) {
					map.put("vai01", Long.parseLong(m.get("vai01").toString()));
				}
			}
		}
		return vaj1;
	}

	private boolean checkPatient9(long vaa07) throws Exception {
		return hoschargeDao.checkPatient9(vaa07) > 0;
	}

	private boolean checkPatient5(long vaa07) throws Exception {
		return hoschargeDao.checkPatient5(vaa07) > 0;
	}

	private boolean checkPatient4(long vaa07) throws Exception {
		return hoschargeDao.checkPatient4(vaa07) > 0;
	}

	private boolean checkParam() throws Exception {
		return hoschargeDao.checkParam() > 0;
	}

	private boolean checkParam1() throws Exception {
		return hoschargeDao.checkParam1() > 0;
	}

	private boolean checkPatient(Map map) throws Exception {
		return hoschargeDao.checkPatient(map) == 0;
	}

	private boolean checkPatient_VBU01(Map map) throws Exception {
		return hoschargeDao.checkPatient_VBU01(map) > 0;
	}

	private boolean checkBCE1(long BCE01A) throws Exception {
		return hoschargeDao.checkBCE1(BCE01A) == 0;
	}

	private boolean checkBCK01B(List<Map<String, Object>> vai1) throws Exception {
		for (Map<String, Object> map : vai1) {
			if (map.get("bck01b") == null || "0".equals(map.get("bck01b").toString())) {
				return true;
			}
		}
		return false;
	}

	private boolean checkBCE02A(List<Map<String, Object>> vai1) throws Exception {
		for (Map<String, Object> map : vai1) {
			if (map.get("bce02a") == null || "".equals(map.get("bce02a").toString())) {
				return true;
			}
		}
		return false;
	}

	private boolean checkBCK01C(List<Map<String, Object>> vaj1) throws Exception {
		for (Map<String, Object> map : vaj1) {
			if (map.get("bck01c") == null || "0".equals(map.get("bck01c").toString())) {
				return true;
			}
		}
		return false;
	}

	private boolean checkBCE02B(List<Map<String, Object>> vaj1) throws Exception {
		for (Map<String, Object> map : vaj1) {
			if (map.get("bce02b") == null || "0".equals(map.get("bce02b").toString())) {
				return true;
			}
		}
		return false;
	}

	private boolean checkBCK01E(List<Map<String, Object>> vaj1) throws Exception {
		for (Map<String, Object> map : vaj1) {
			if (map.get("bck01e") == null || "0".equals(map.get("bck01e").toString())
					&& ("0".equals(map.get("BDN01").toString()) || "1".equals(map.get("BDN01").toString())
							|| "2".equals(map.get("BDN01").toString()) || "3".equals(map.get("BDN01").toString()))) {
				return true;
			}
		}
		return false;
	}

	private boolean checkParam2() throws Exception {
		return hoschargeDao.checkParam2() > 0;
	}

	private int getABC14(String ABC02) throws Exception {
		return hoschargeDao.getABC14(ABC02);
	}

	private List<Map<String, Object>> tmpNewVAI1(List<Map<String, Object>> vai1) throws Exception {
		List<Map<String, Object>> tmpNewVAI1 = new ArrayList<>();
		for (Map<String, Object> map : vai1) {
			if ("0".equals(map.get("vai01").toString())) {
				tmpNewVAI1.add(map);
			}

		}
		return tmpNewVAI1;

	}

	private List<Map<String, Object>> tmpNewVAJ1(List<Map<String, Object>> vaj1) throws Exception {
		List<Map<String, Object>> tmpNewVAJ1 = new ArrayList<>();
		for (Map<String, Object> map : vaj1) {
			if ("0".equals(map.get("vai01").toString())) {
				tmpNewVAJ1.add(map);
			}

		}
		return tmpNewVAJ1;

	}

	private List<Map<String, Object>> tmpOldVAJ1(List<Map<String, Object>> vaj1) throws Exception {
		List<Map<String, Object>> tmpOldVAJ1 = new ArrayList<>();
		for (Map<String, Object> map : vaj1) {
			if (Long.parseLong(map.get("vai01").toString()) > 0) {
				tmpOldVAJ1.add(map);
			}

		}
		return tmpOldVAJ1;

	}

	private boolean checkParam3() throws Exception {
		return hoschargeDao.checkParam3() > 0;
	}

	private List<Map<String, Object>> tmpNewVAJ1_VAJ53(List<Map<String, Object>> tmpNewVAJ1) throws Exception {
		for (Map<String, Object> map : tmpNewVAJ1) {
			if ("0".equals(map.get("bdn01").toString()) || "1".equals(map.get("bdn01").toString())
					|| "2".equals(map.get("bdn01").toString()) || "3".equals(map.get("bdn01").toString())) {
				map.put("vaj53", 2);
			}
		}
		return tmpNewVAJ1;
	}

	private List tmpNewVAI1_VAI01_VAI04_VAI22_VAI23(List<Map<String, Object>> tmpNewVAI1,
			List<Map<String, Object>> vaj1) throws Exception {
		DecimalFormat df = new DecimalFormat("0.00");
		for (Map<String, Object> map : tmpNewVAI1) {
			String VAI00 = map.get("vai00").toString();
			long vai01 = getNewId.nextId();
			String vai04 = "I" + String.valueOf(vai01).substring(0, 18);
			double VAI22 = 0, VAI23 = 0;
			for (Map<String, Object> map2 : vaj1) {
				if (VAI00.equals(map.get("vai00").toString())) {
					VAI22 += Double.parseDouble(map2.get("vaj36").toString());
					VAI23 += Double.parseDouble(map2.get("vaj38").toString());
				}
			}
			map.put("vai01", vai01);
			map.put("vai04", vai04);
			map.put("vai22", df.format(VAI22));
			map.put("vai23", df.format(VAI23));

		}

		return tmpNewVAI1;
	}

	private List setVAI01_VAI04(List<Map<String, Object>> tmpNewVAI1, List<Map<String, Object>> vai1) throws Exception {
		for (Map<String, Object> map : vai1) {
			for (Map<String, Object> m : tmpNewVAI1) {
				if (map.get("vai00").toString().equals(m.get("vai00"))) {
					if (map.get("vai01").toString().equals("0")) {
						map.put("vai01", m.get("vai01"));
						map.put("VAI04", m.get("vai04"));
					}
				}
			}
		}
		return vai1;
	}

	private List tmpNewVAJ1_VAJ01(List<Map<String, Object>> tmpNewVAJ1, List<Map<String, Object>> vai1)
			throws Exception {
		for (Map<String, Object> map : tmpNewVAJ1) {
			for (Map<String, Object> m : vai1) {
				if (map.get("vai00").toString().equals(m.get("vai00").toString())) {
					map.put("vai01", m.get("vai01"));
				}
			}
		}

		return tmpNewVAJ1;
	}

	private List VAJ1_VAJ01(List<Map<String, Object>> vaj1, List<Map<String, Object>> vai1) throws Exception {
		for (Map<String, Object> map : vaj1) {
			for (Map<String, Object> m : vai1) {
				if (map.get("vai00").toString().equals(m.get("vai00").toString())) {
					map.put("vai01", m.get("vai01"));
				}
			}
		}

		return vaj1;
	}

	private List tmpOldVAJ1_VAJ24_VAJ25(List<Map<String, Object>> tmpOldVAJ1) throws Exception {
		for (Map<String, Object> map : tmpOldVAJ1) {
			String BDN01 = map.get("bdn01").toString();
			long BBY01 = Long.parseLong(map.get("bby01").toString());
			double VAJ25 = Double.parseDouble(map.get("vaj25").toString());
			double VAJ30 = Double.parseDouble(map.get("vaj30").toString());
			double VAJ31 = Double.parseDouble(map.get("vaj31").toString());
			double VAJ32 = Double.parseDouble(map.get("vaj32").toString());
			double VAJ33 = Double.parseDouble(map.get("vaj33").toString());
			double VAJ34 = Double.parseDouble(map.get("vaj34").toString());
			String VAJ35 = map.get("vaj35").toString();
			String FAB03 = map.get("vaj35").toString();
			double VAJ24 = Double.parseDouble(map.get("vaj24").toString());
			if ("0".equals(BDN01) || "1".equals(BDN01) || "2".equals(BDN01) || "3".equals(BDN01)) {
				VAJ35 = hoschargeDao.getBBY08(BBY01);
				VAJ33 = VAJ32 * VAJ30 / VAJ31;
				VAJ25 = VAJ25 * VAJ34;
				VAJ24 = VAJ24 * VAJ34;
				map.put("vaj24", VAJ24);
				map.put("vaj25", VAJ25);
				map.put("vaj32", VAJ32);
				map.put("vaj33", VAJ33);
				map.put("vaj35", VAJ35);
			}

		}

		return tmpOldVAJ1;
	}

	private List tmpNewVAJ1_VAJ24_VAJ25(List<Map<String, Object>> tmpNewVAJ1) throws Exception {
		for (Map<String, Object> map : tmpNewVAJ1) {
			String BDN01 = map.get("bdn01").toString();
			long BBY01 = Long.parseLong(map.get("bby01").toString());
			double VAJ25 = Double.parseDouble(map.get("vaj25").toString());
			double VAJ30 = Double.parseDouble(map.get("vaj30").toString());
			double VAJ31 = Double.parseDouble(map.get("vaj31").toString());
			double VAJ32 = Double.parseDouble(map.get("vaj32").toString());
			double VAJ33 = Double.parseDouble(map.get("vaj33").toString());
			double VAJ34 = Double.parseDouble(map.get("vaj34").toString());
			String VAJ35 = map.get("vaj35").toString();
			String FAB03 = map.get("vaj35").toString();
			double VAJ24 = Double.parseDouble(map.get("vaj24").toString());
			if ("0".equals(BDN01) || "1".equals(BDN01) || "2".equals(BDN01) || "3".equals(BDN01)) {
				VAJ35 = hoschargeDao.getBBY08(BBY01);
				VAJ33 = VAJ32 * VAJ30 / VAJ31;
				VAJ25 = VAJ25 * VAJ34;
				VAJ24 = VAJ24 * VAJ34;
				map.put("vaj24", VAJ24);
				map.put("vaj25", VAJ25);
				map.put("vaj32", VAJ32);
				map.put("vaj33", VAJ33);
				map.put("vaj35", VAJ35);
			}
			map.put("vaj01", getNewId.nextId());
		}
		return tmpNewVAJ1;
	}

	private double getTotalFee(List<Map<String, Object>> tmpNewVAJ1) throws Exception {
		double totalFee = 0;
		for (Map<String, Object> map : tmpNewVAJ1) {
			totalFee += Double.parseDouble(map.get("vaj38").toString());
		}

		return totalFee;
	}

	private boolean checkBGE1(Map map) throws Exception {
		return hoschargeDao.checkBGE1(map) == 0;

	}

	// HORate_BGE1_Update 私人收费项目
	public ModelVo execHORate_BGE1_Update(Map map) throws Exception {
		ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
		String xml = map.get("Xml").toString();
		JSONObject jsonObject = JSONObject.fromObject(xml);
		List<Map<String, Object>> vaj1 = JsonUtil.getList(jsonObject.getJSONArray("VAJ1").toString());

		long BBY01, BGE01 = getNewId.nextId();
		for (Map<String, Object> map2 : vaj1) {
			BBY01 = Long.parseLong(map2.get("bby01").toString());
			map.put("BBY01", BBY01);
			map.put("BGE01", BGE01);
			if (checkBGE1(map)) {
				hoschargeDao.insertBGE1(map);
			} else {
				hoschargeDao.updateBGE1(map);
			}
		}

		return vo;
	}

	public boolean checkCAM1(Map map) throws Exception {
		return hoschargeDao.checkCAM1(map) > 0;
	}

	public ModelVo execHOPatient_VAO1_Update(Map map) throws Exception {
		ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
		Long CAM01 = Long.parseLong(map.get("CAM01").toString());
		if (map.get("VAO15")!=null&&!"".equals(map.get("VAO15").toString())) {
			if (map.get("BAK01") == null || "0".equals(map.get("BAK01").toString())) {
				if (checkCAM1(map)) {
					CAM01 = hoschargeDao.getCAM01(map.get("VAO15").toString());
					map.put("BAK01", hoschargeDao.getBAK01(CAM01));

				} else {
					// 新增病人诊断
					map.put("CAM01", getNewId.nextId());
					hoschargeDao.insertVAO2(map);
				}
				if (map.get("VAO01") == null || "0".equals(map.get("VAO01").toString())) {
					map.put("VAO01", getNewId.nextId());
					if ("1".equals(map.get("ACF01").toString())) {
						hoschargeDao.insertVAO1(map);
					} else {
						// 判断住院病人是否存在诊断
						if (hoschargeDao.checkVAO2(map) == 0) {
							hoschargeDao.saveVAO2(map);
						}

					}
				} else {
					hoschargeDao.updateVAO2(map);

				}

			}
		}

		return vo;
	}
	private String gparam60()throws Exception{
		return hoschargeDao.gparam60();
	}
	//药品项目明细
	public ModelVo queryFeeDetail(Map map,int currPage,int pageSize)throws Exception{
		ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
		map.put("CDate", DateUtils.getDateStr(new Date())+" 00:00:00");
		map.put("gparam60", gparam60());
		Page pg = new Page();
		try {
			pg = hoschargeDao.queryFeeDetail(map,currPage,pageSize);

		} catch (Exception e) {
			e.printStackTrace();
			vo.setResult(StaticKeys.OH_FALSE);
			return vo;
		}
		vo.setList(pg.getList());
		vo.setResult(StaticKeys.OH_SUCCESS);
		vo.setRows(pg.getList());
		vo.setTotal(pg.getTotalNumber());
		return vo;
	}
	public ModelVo queryMedicinaItem(Map map)throws Exception{
		ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
		map.put("ABC14", hoschargeDao.getABC14(map.get("ABC02").toString()));
		List ls = null;
		try {
			ls = hoschargeDao.queryMedicinaItem(map);

		} catch (Exception e) {
			e.printStackTrace();
			vo.setResult(StaticKeys.OH_FALSE);
			return vo;
		}
		vo.setList(ls);
		vo.setResult(StaticKeys.OH_SUCCESS);
		vo.setRows(ls);
		return vo;
	}
	public ModelVo queryItemTree()throws Exception{
		ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
		List ls = null;
		try {
			ls = hoschargeDao.queryItemTree();

		} catch (Exception e) {
			e.printStackTrace();
			vo.setResult(StaticKeys.OH_FALSE);
			return vo;
		}
		vo.setList(ls);
		vo.setResult(StaticKeys.OH_SUCCESS);
		vo.setRows(ls);
		return vo;
	}
	public ModelVo queryOtherFeeItem(Map map)throws Exception{
		ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
		map.put("BBY34", hoschargeDao.getBBY34(map));
		
		List ls = null;
		try {
			ls = hoschargeDao.queryOtherFeeItem(map);

		} catch (Exception e) {
			e.printStackTrace();
			vo.setResult(StaticKeys.OH_FALSE);
			return vo;
		}
		vo.setList(ls);
		vo.setResult(StaticKeys.OH_SUCCESS);
		vo.setRows(ls);
		return vo;
	}
	
	public ModelVo queryTreatmentList()throws Exception{
		ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
		
		List ls = null;
		try {
			ls = hoschargeDao.queryTreatmentList();

		} catch (Exception e) {
			e.printStackTrace();
			vo.setResult(StaticKeys.OH_FALSE);
			return vo;
		}
		vo.setList(ls);
		vo.setResult(StaticKeys.OH_SUCCESS);
		vo.setRows(ls);
		return vo;
		
	}
	public ModelVo querypatientInfo(Map map)throws Exception{
       ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
		map.put("param406", hoschargeDao.param406());
		List ls = null;
		try {
			ls = hoschargeDao.querypatientInfo(map);

		} catch (Exception e) {
			e.printStackTrace();
			vo.setResult(StaticKeys.OH_FALSE);
			return vo;
		}
		vo.setList(ls);
		vo.setResult(StaticKeys.OH_SUCCESS);
		vo.setRows(ls);
		return vo;
	}
	public ModelVo queryMaterialItem(Map map,int currPage,int pageSize)throws Exception{
				  ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
						map.put("lDate",DateUtils.getDateStr(new Date())+" 00:00:00");
						map.put("gparam60", hoschargeDao.gparam60());
						Page pg = new Page();
						try {
							pg=hoschargeDao.queryMaterialItem(map, currPage, pageSize);

						} catch (Exception e) {
							e.printStackTrace();
							vo.setResult(StaticKeys.OH_FALSE);
							return vo;
						}
						vo.setList(pg.getList());
						vo.setResult(StaticKeys.OH_SUCCESS);
						vo.setRows(pg.getList());
						vo.setTotal(pg.getTotalNumber());
						return vo;		
				
	}
	public ModelVo queryItems(Map map,int currPage,int pageSize)throws Exception{
		  ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
			map.put("CDate",DateUtils.getDateStr(new Date())+" 00:00:00");
			map.put("gparam60", hoschargeDao.gparam60());
			Page pg = new Page();
			try {
				pg=hoschargeDao.queryItems(map, currPage, pageSize);

			} catch (Exception e) {
				e.printStackTrace();
				vo.setResult(StaticKeys.OH_FALSE);
				return vo;
			}
			vo.setList(pg.getList());
			vo.setResult(StaticKeys.OH_SUCCESS);
			vo.setRows(pg.getList());
			vo.setTotal(pg.getTotalNumber());
			return vo;
	}
	public ModelVo getDrugPrice(Map map)throws Exception{
		ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
		List ls = null;
		try {
			ls = hoschargeDao.getDrugPrice(map);

		} catch (Exception e) {
			e.printStackTrace();
			vo.setResult(StaticKeys.OH_FALSE);
			return vo;
		}
		vo.setList(ls);
		vo.setResult(StaticKeys.OH_SUCCESS);
		vo.setRows(ls);
		return vo;
	}
	public ModelVo getItemExecDept(Map map)throws Exception{
		ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
		List ls = null;
		try {
			ls = hoschargeDao.getItemExecDept(map);

		} catch (Exception e) {
			e.printStackTrace();
			vo.setResult(StaticKeys.OH_FALSE);
			return vo;
		}
		vo.setList(ls);
		vo.setResult(StaticKeys.OH_SUCCESS);
		vo.setRows(ls);
		return vo;
		
		
	}
	   public ModelVo execHORateVAJ2Recompute(Map map)throws Exception{
		   ModelVo vo = new ModelVo(StaticKeys.OH_SUCCESS);
//		    long VAI01;  
		    long EmpId;
//		    long VAK01A;	    
//		    String VAI04 ;
//		    String VAK04 ;
	        String EmpNo;
	        String EmpName;
//	        String HostIp;
//	        String HostName;
//	        long DeptId;
//	        String ZAE01;
//	        long BBY01;
//	        long VAJ01;
//	        long BCK01D;
//	        String DeptNo;
//	        String DeptName;
//	        String HostMac;
//	        String FileVer;
//	        double VAI22;
//	        double VAI23 ;
	        String OABC02;
	        String BDate=DateUtils.getDateString(new Date());
//	        double VAJ32;
//	        double SumMoney;
//	        double BDN01;
//	        double VAJ01A ;
//	        double VBM06;
//	        double Memo;
//	        double VAJ25;
	        String xml = map.get("XML").toString();
			Map<String, Object> operInfo = JsonUtil.getMap(xml);
			EmpId = Long.parseLong(operInfo.get("empid").toString()); 
			EmpNo = operInfo.get("empno").toString();
			EmpName = operInfo.get("empname").toString();
//			DeptId = Long.parseLong(operInfo.get("deptid").toString());
//			DeptNo = operInfo.get("deptno").toString();
//			DeptName = operInfo.get("deptname").toString();
//			HostIp = operInfo.get("hostip").toString();
//			HostName = operInfo.get("hostname").toString();
//			HostMac = operInfo.get("hostmac").toString();
			if(hoschargeDao.sysParams()>0&&checkVIP(map)){
				vo.setResult(StaticKeys.OH_FALSE);
				vo.setResultMsg("已绑定会员卡类型，禁止修改病人费别");
				return vo;
			}
			if(checkVAJ2(map)){
				vo.setResult(StaticKeys.OH_FALSE);
				vo.setResultMsg("病人待收费记录信息为空");
				return vo;
			}
	        List<Map<String,Object>> tmpNewVAJRecmp = tmpNewVAJRecmp(map);
	        if(tmpNewVAJRecmp.size()==0){
	        	vo.setResult(StaticKeys.OH_FALSE);
				vo.setResultMsg("要求存在未上传到医保、不是退费产生的或会员卡已扣费的明细才允许进行折扣，故不能进行重算操作");
				return vo;
	        }
	        OABC02=getOABC02(map);
	        if(OABC02==null){
	        	OABC02="";
	        }
	        //按费别检索所有能打折明细折扣记录
	        List tmpVAJRecmpEd = tmpVAJRecmpEd(tmpNewVAJRecmp, map);
	        map.put("tmpVAJRecmpEd",tmpVAJRecmpEd);
	        //修改病人费别 类别
	        hoschargeDao.updateVAE1_VAJ2_VAA1(map);
		    if(!map.get("ABC02").toString().equals(OABC02)){
		    	//保存病人信息变动记录
		    	HashMap hs = new HashMap();
		    	hs.put("ZAE01", getNewId.nextId());
		    	hs.put("TNAME", "VAE1");
		    	hs.put("CNAME", "ABC02");
		    	hs.put("ZAE04", map.get("VAA01").toString());
		    	hs.put("ZAE05", map.get("VAA07").toString());
		    	hs.put("ZAE06", OABC02);
		    	hs.put("ZAE07", map.get("ABC02").toString());
		    	hs.put("ZAE08", "住院病人费别变动");
		    	hs.put("BCE01", EmpId);
		    	hs.put("BCE03", EmpName);
		    	hs.put("AType", 1);
		    	hoschargeDao.HORate_ZAE1_Update(hs);
		    }
		    //会员折上折处理
		    double SubRate;
		    //获取会员折上折比例
		    String sRate = hoschargeDao.getSubRate(map);
		    if(sRate!=null){
		    	SubRate = Double.parseDouble(sRate);
		    	if(SubRate>0&&SubRate<1){
		    		map.put("SubRate", SubRate);
		    		hoschargeDao.update_VAJ2(map);
		    	}
		    }
		    //费用明细折扣后金额变化记录
		    List tmpVAJAChange = hoschargeDao.tmpVAJAChange(map);
		    if(tmpVAJAChange.size()>0){
		    	map.put("EmpNo", EmpNo);
		    	map.put("EmpName", EmpName);
		    	map.put("BDate", BDate);
		    	hoschargeDao.insertVAJA(map);
		    }
//		    //病人保险就诊记录
//		    if(checkIAR1(map)){
//		    	map.put("CheckoutType", 1);
//		    	vo=Insur_InHosCheckOut_Entry(map,vo);
//		    }
		   return vo;
	     }
	   private boolean checkVIP(Map map)throws Exception{
		   return hoschargeDao.checkVIP(map)>0;
	   }
	   private boolean checkVAJ2(Map map)throws Exception{
		   return hoschargeDao.checkVAJ2(map)==0;
	   }
	   private List tmpNewVAJRecmp(Map map)throws Exception{
		   return hoschargeDao.tmpNewVAJRecmp(map);
	   }
	   private String getOABC02(Map map)throws Exception{
		   return  hoschargeDao.getOABC02(map);
	   }
	   private List tmpVAJRecmpEd(List<Map<String,Object>> tmpNewVAJRecmp,Map map)throws Exception{
		   List<Map<String,Object>> tmpVAJRecmpEd = new ArrayList<>();
		   for (Map<String, Object> map2 : tmpNewVAJRecmp) {
			   long VAJ01 = map2.get("VAJ01")==null?0:Long.parseLong(map2.get("VAJ01").toString());
			   long BBY01 = map2.get("bby01")==null?0:Long.parseLong(map2.get("bby01").toString());
			   double VAJ32 = map2.get("vaj32")==null?0:Double.parseDouble(map2.get("vaj32").toString());
			   double SumMoney = map2.get("vaj36")==null?0:Double.parseDouble(map2.get("vaj36").toString());
			   double VAJ25 =map2.get("vaj25")==null?0:Double.parseDouble(map2.get("vaj25").toString());
			   String BDN01 = map2.get("bdn01")==null?"":map2.get("bdn01").toString();
			   long BCK01D = map2.get("bck01d")==null?0:Long.parseLong(map2.get("bck01d").toString());
			   long VAJ01A = map2.get("vaj01a")==null?0:Long.parseLong(map2.get("vaj01a").toString()); 
			   if("0".equals(BDN01)||"1".equals(BDN01)||"2".equals(BDN01)||"3".equals(BDN01)){
				   HashMap m = new HashMap();
				   m.put("VAJ01A", VAJ01A);
				   m.put("BBY01", BBY01);
				   if(!(VAJ01A>0)&&checkBCR1(m)){
					   map.put("BCK01D", BCK01D);
					   map.put("BBY01", BBY01);
					   VAJ32 = hoschargeDao.getVAJ32(map);
					   SumMoney = VAJ32*VAJ25;
				   }
				   
			   }
			   map.put("VAJ01", VAJ01);
			   map.put("BBY01", BBY01);
			   map.put("SumMoney", SumMoney);
			   map.put("VAJ32", VAJ32);
			   map.put("BDate", DateUtils.getDateString(new Date()));
			   List vaj = hoschargeDao.getTmpVAJRecmpEd1(map);
			   tmpVAJRecmpEd.addAll(vaj);
			   if(!checkVAJ01(vaj, VAJ01A)){
				   vaj = hoschargeDao.getTmpVAJRecmpEd2(map);
				   tmpVAJRecmpEd.addAll(vaj);
			   }
			   
		   }
		   return tmpVAJRecmpEd;
	   }
	   private boolean checkBCR1(Map m)throws Exception{
		   return hoschargeDao.checkBCR1(m)>0;
	   }
	   private boolean checkVAJ01(List<Map<String,Object>> vaj,long VAJ01)throws Exception{
		   for (Map<String, Object> map : vaj) {
			 if(map.get("VAJ01").toString().equals(String.valueOf(VAJ01))){
				 return true;
			 }
		 }
		   return false;
	   }
	   private boolean checkIAR1(Map map)throws Exception{
		   return hoschargeDao.checkIAR1(map)>0;
	   } 
	   //Insur_InHosCheckOut_Entry 病人保险结算
	   public ModelVo  Insur_InHosCheckOut_Entry(Map map,ModelVo vo)throws Exception{
		   String ABU01=null;
		   if(hoschargeDao.checkIAJ1()>0){
			   ABU01 = hoschargeDao.getIAJ05();
		   }
		   if(ABU01==null){
			   vo.setResult(StaticKeys.OH_FALSE);
				vo.setResultMsg("您没有取得住院保险模拟结算的权限，或设置有误，请检查是否启用保险模拟结算和设置好全国行政区划编码");
				return vo;
		   }
		   
		   return vo;
	   }
	   //<VAJ><Ie RecordID="1" selected="1" VAJ01="204094" VAA01="227" VAA07="140" VAI01="46807" VAJ25="1" BBY01="7800" BDN01="2" VAJ36="10.12" VAJ37="10.12" VAJ38="10.12" VAJ61="10.12"/></VAJ><OperInfo UserId="1" UserCode="8080" UserName="系统管理员" UserLoginDate="2016-06-23 09:12:19" HostName="PC201403010064" HostIp="192.168.56.1" HostMac="C0-3F-D5-B7-47-0D" EmpId="1" EmpNo="8080" EmpName="系统管理员" DeptId="3" DeptNo="03" DeptName="信息科" FileVer="0008.0000.0006.0032"/>
	   public ModelVo execHORate_VAJ2_BatchDel(Map map)throws Exception{
		    ModelVo vo = new ModelVo();
		    String xml = map.get("Xml").toString();
		    JSONObject object = JSONObject.fromObject(xml);
		    Map<String,Object> VAJ1 = JsonUtil.getMap(object.getJSONObject("VAJ1").toString());
		    Map<String,Object> operInfo = JsonUtil.getMap(object.getJSONObject("OperInfo").toString());
		    if(hoschargeDao.checkVAJ2Cout(VAJ1)>0){
		    	 vo.setResult(StaticKeys.OH_FALSE);
					vo.setResultMsg("销账明细中包含已销账明细，不能销账");
					return vo;
		    }
		    double TotalFee = Double.parseDouble(VAJ1.get("vaj38").toString());
		    long VAA01 = Long.parseLong((VAJ1.get("vaa01").toString()));
		    long VAA07 = Long.parseLong((VAJ1.get("vaa07").toString()));
		    int IsRemainFee=0;
		    map.put("tmpVAJ1", VAJ1);
		    List tmpVAJ1 = hoschargeDao.tmpVAJ1(map);
		    map.put("tmpVAJ1", VAJ1);
		    List tmpVAI1 = tmpVAI1(VAJ1);
		    List tmpNewVAJ1 = tmpNewVAJ1(map);
		    //部分退费明细
		    List tmpRemnantVAJ1=null;
		    if(hoschargeDao.checkOut(map)>0){
		    	List ls = hoschargeDao.tmpRemnantVAJ1(map);
		    	if(ls.size()>0){
		    		IsRemainFee=1;
		    		tmpRemnantVAJ1 = tmpRemnantVAJ1(map);
		    	}
		    	
		    }
		    
		    
		    
		    
		    
		    
		    
		    return vo;
		   
	   }
	   private List tmpVAI1(Map VAJ1)throws Exception{
		   List<Map<String,Object>> tmpVAI1 = hoschargeDao.tmpVAI1(VAJ1);
		   for (Map<String, Object> map : tmpVAI1) {
			   long id= getNewId.nextId();
			 map.put("VAI01",id);
			 map.put("VAI04", "I"+id);
		   }
		   return tmpVAI1;
	   }
	   private List tmpNewVAJ1(Map map)throws Exception{
		   List<Map<String,Object>> tmpNewVAJ1=hoschargeDao.tmpNewVAJ1(map);
		   for (Map<String, Object> map2 : tmpNewVAJ1) {
			  long id=getNewId.nextId();
			  map2.put("vaj01", id);
			  map2.put("vaj09", id);
			  if(map2.get("bdn01").toString().equals("1")||map2.get("bdn01").toString().equals("2")||map2.get("bdn01").toString().equals("3")){
				  if(map2.get("vaj48").toString().equals("0")&&map2.get("vaj53").toString().equals("0")){
					  map2.put("vaj48", 0);
					  map2.put("vaj53", 2);
				  }
				  if(Long.parseLong(map2.get("vaj48").toString())>0&&map2.get("vaj53").toString().equals("1")){
					  map2.put("vaj48", 0);
					  map2.put("vaj53", 0);
				  }
			  }
			  if(map2.get("bdn01").toString().equals("4")){
				  map2.put("vaj48", 0);
				  map2.put("vaj53", 0);
			  }
		    }
		   return tmpNewVAJ1;
	   }
	   private List tmpRemnantVAJ1(Map map)throws Exception{
		   List<Map<String,Object>> tmpRemnantVAJ1 = hoschargeDao.tmpRemnantVAJ12(map);
		   for (Map<String, Object> map2 : tmpRemnantVAJ1) {
			map2.put("vaj01", getNewId.nextId());
		   }
		   return tmpRemnantVAJ1;
	   }
	   public ModelVo printPrompt(Map map,int currPage,int pageSize)throws Exception{
		   ModelVo mo = new ModelVo();
			Page pg = new Page();
			try {
				pg = hoschargeDao.printPrompt(map, currPage, pageSize);

			} catch (Exception e) {
				e.printStackTrace();
				mo.setResult(StaticKeys.OH_FALSE);
				return mo;
			}
			mo.setList(pg.getList());
			mo.setResult(StaticKeys.OH_SUCCESS);
			mo.setRows(pg.getList());
			mo.setRecords(pg.getTotalNumber());
			mo.setTotal(pg.getTotalNumber());
			return mo;
	   }
	   public ModelVo dayList(Map map,int currPage,int pageSize)throws Exception{
		   ModelVo mo = new ModelVo();
			Page pg = new Page();
			try {
				pg = hoschargeDao.dayList(map, currPage, pageSize);

			} catch (Exception e) {
				e.printStackTrace();
				mo.setResult(StaticKeys.OH_FALSE);
				return mo;
			}
			mo.setList(pg.getList());
			mo.setResult(StaticKeys.OH_SUCCESS);
			mo.setRows(pg.getList());
			mo.setTotal(pg.getTotalNumber());
			return mo;
		   
	   }
	   public ModelVo feeTotal(Map map,int currPage,int pageSize)throws Exception{
		   ModelVo mo = new ModelVo();
			Page pg = new Page();
			try {
				pg = hoschargeDao.feeTotal(map, currPage, pageSize);

			} catch (Exception e) {
				e.printStackTrace();
				mo.setResult(StaticKeys.OH_FALSE);
				return mo;
			}
			mo.setList(pg.getList());
			mo.setResult(StaticKeys.OH_SUCCESS);
			mo.setRows(pg.getList());
			mo.setTotal(pg.getTotalNumber());
			return mo;
		   
	   }
}
